<?php

namespace app\services;

use support\Cache;

class TokenService
{
    const SLAT = 'abcedf';

    public static function generate($userId)
    {
        $token = md5($userId . random_int(10000, 99999) . self::SLAT);

        Cache::set($token, $userId, 24 * 3600 * 7);
        return $token;
    }

    public static function getUserId($token)
    {
        return Cache::get($token);
    }

    public static function destroy($token)
    {
        Cache::delete($token);
    }
}